<?php
	$page = isset($_GET['page']) ? $_GET['page'] : NULL;
	
	switch($page){
		default:
			home();
			break;
		case "request_account":
			request_account();
			break;
		case "forgot_password":
			forgot_password();
			break;
		case "logout":
			logout();
			break;
		case "resources":
			testbed_resources();
			break;
		case "policy":
			policy();
			break;
		case "contact":
			contact();
			break;
		case "my_account":
			validating_authentication();
			my_account();
			break;
		case "reservation":
			validating_authentication();
			include ("system/scheduler.php");
			break;
		case "my_reservations":
			validating_authentication();
			include ("system/getUserReservations.php");
			break;
		case "manager_user":
			validating_authentication('admin');
			manager_user();
			break;
		case "edit_user":
			validating_authentication('admin');
			edit_user();
			break;
		case "pendency":
			validating_authentication('admin');
			pendency();
			break;
		case "manager_resources":
			validating_authentication('admin');
			manager_resources();
			break;
		case "edit_resource":
			validating_authentication('admin');
			edit_resource();
			break;
		case "add_resource":
			validating_authentication('admin');
			add_resource();
			break;
		case "manager_pxeimages":
			validating_authentication('admin');
			manager_pxeimages();
			break;
		case "add_pxeimage":
			validating_authentication('admin');
			add_pxeimage();
			break;
		case "edit_pxeimage":
			validating_authentication('admin');
			edit_pxeimage();
			break;
		case "manager_motherboards":
			validating_authentication('admin');
			manager_motherboards();
			break;
		case "add_motherboard":
			validating_authentication('admin');
			add_motherboard();
			break;
		case "edit_motherboard":
			validating_authentication('admin');
			edit_motherboard();
			break;
	}
	
	function home(){
		echo "<div id='text'>
				<div class='title'>OMF UFG Testbed</div>
				
				<div>Welcome to the <b>UFG local testbed island</b>!</div>
				
				<div>This page gives access to a remote experimental infrastructure (or testbed) for tests with computer networks and distributed systems, mainly involving wireless and wired devices. This testbed is part of the project FIBRE, an initiative between Brazil and Europe.</div>
				
				<div>The UFG island is operated by the Computer Networks and Distributed Systems Laboratory (LABORA), from the <a href='http://www.inf.ufg.br/' target='_blank'>Institute of Informatics</a> of Federal University of Goiás (UFG).</div>
			
				<br/>
				
				<div class='title'>Available CMFs in this island</div>
				
				<div><b>LABORA</b> (Laboratório de Redes de Computadores e Aplicações Distribuídas) Scheduler is a system for resource reservation that allow to slice a wireless testbed. The system can also manages the resources and users. A user can choose devices (or nodes) and frequencies (or channel) in order to make experiments. LABORA Scheduler has been developed by LABORA group at Federal University of Goias, in Brazil.</div>
				
				<div><b>OMF</b> (cOntrol and Management Framework) is a set of tools to control and management testbeds. OMF allows to remotely setup experiments and collect results from different types of devices, such as computers, routes, switches, wireless AP, etc. OMF has been initially by WINLAB at Rutgers University, in USA. Nowadays, OMF is open-source initiative, receiving support from WINLAB, NITlab, NICTA, and other institutions and individuals.</div>
			</div>
		";
	}
	
	function testbed_resources() {
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Island resources</div>
				
				<div>There are 8 <b><a href='http://nitlab.inf.uth.gr/NITlab/index.php/hardware/wireless-nodes/icarus-nodes' target='_blank'>Icarus Nodes</a></b> available for remote experimentation.</div>
			 </div>
		";
	}
	
	function policy() {
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Island policy</div>
				
				<div>The resources are freely available for non-profit usage.</div>
			 </div>
		";
	}

	function contact(){
		if(!isset($_SESSION['captcha']))
			$_SESSION['captcha'] = substr(md5(uniqid(time(), true)), 0, 7);
		
		$send_email = false;
		if(isset($_POST['sbmt_contact'])) {
			$non_empty_fields = array('name','email','subject','message','captcha');
			
			$empty = false;
			for($i = 0; $i < count($non_empty_fields); $i++){
				if(empty($_POST[$non_empty_fields[$i]])){
					$empty = true;
					set_message('Fill out all fields to continue.','alert',1);
					break;
				}
			}
			
			if(!$empty){
				if( $_POST['captcha'] != $_SESSION['captcha'] ) {
					set_message('Wrong captcha.','error',1);
				} else {
					$sender = array('email' => $_POST['email'], 'name' => $_POST['name']);
					$receiver = array();
					$receiver[] = array('email' => ISLAND_CONTACT_EMAIL, 'name' => 'Fibre - '.ISLAND_ACRONYM.' island');

					$send_email = send_mail($sender, $receiver, $_POST['subject'], $_POST['message']);
					set_message('Contact email sent successfully!','success',1);
				}
			}
		}
			
		$_SESSION['captcha'] = substr(md5(uniqid(time(), true)), 0, 7);
		
		$name = (isset($_POST['name']) && !$send_email) ? $_POST['name'] : "";
		$email = (isset($_POST['email']) && !$send_email) ? $_POST['email'] : "";
		$subject = (isset($_POST['subject']) && !$send_email) ? $_POST['subject'] : "";
		$message = (isset($_POST['message']) && !$send_email) ? $_POST['message'] : "";
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Island contact</div>
				
				<div>
					<form action='' method='POST' id='registration'>
						<table>
							<tr>
								<td>Name:</td>
								<td><input type='text' name='name' value='".$name."'></td>
							</tr>
							<tr>
								<td>E-mail:</td>
								<td><input type='text' name='email' value='".$email."'></td>
							</tr>
							<tr>
								<td>Subject:</td>
								<td><input type='text' name='subject' value='".$subject."'></td>
							</tr>
							<tr>
								<td>Message:</td>
								<td><textarea name='message'>".$message."</textarea></td>
							</tr>
							<tr>
								<td></td>
								<td><img src='captcha/captcha.php'/></td>
							</tr>
							<tr>
								<td>Captcha:</td>
								<td><input type='text' name='captcha' size='7'></td>
							</tr>
							<tr>
								<td></td>
								<td><input type='submit' name='sbmt_contact' value='Send'></td>
							</tr>
						</table>
					</form>
				</div>
			 </div>
		";
	}
	
	function my_account(){
		$user_data = api_call('get_users', array('filter' => array($_SESSION[''.SECURITY_SESSION.'']['user_id'])));
		
		if(isset($_POST['sbmt'])){
			$username = $_POST['username'];
			$name = $_POST['name'];
			$email = $_POST['email'];
			$current_password = $_POST['current_password'];
			$password = $_POST['password'];
			$password2 = $_POST['password2'];
			
			if(empty($username) || empty($name) || empty($email))
				set_message('Fill out all fields to continue.','alert',1);
			else{
				$change = array(
							"user_id" => $_SESSION[''.SECURITY_SESSION.'']['user_id'],
							"new_user_data" => array(
													"name" => $name,
													"email" => $email
											   )
						  );
						  
				// Change password:
				if(!empty($password) && !empty($password2) && ($password != $password2)){
					set_message('Passwords do not match.','alert',1);
					$password_error = TRUE;
				}else if(!empty($current_password) && !empty($password) && !empty($password2)){					
					$parameters	=	array(
										'username' => $username,
										'password' => $current_password
									);
									
					$authentication = api_call("authenticate_user", $parameters);
					
					if($authentication['method_result'] > 0)
						$change['new_user_data']['password'] = $password;
					else{
						set_message('Wrong current password.','error',1);
						$password_error = TRUE;
					}
				}
				
				if(!isset($password_error)){
					$modify = api_call("update_user", $change);
					
					if($modify['method_result'] == true)
						set_message('User edited successfully!','success',1);
					else
						set_message('Error to edit this user, try again.','error',1);
				}
			}
		}
		
		if(count($user_data['method_result']) < 1)
			Header("Location: index.php?page=logout");
		
		// Define form default values
		$name = (isset($_POST['name'])) ? $_POST['name'] : $user_data['method_result'][0]['name'];
		$email = (isset($_POST['email'])) ? $_POST['email'] : $user_data['method_result'][0]['email'];
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." My account</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>
					<tr>
						<td>Login Name</td>
						<td><input type='text' name='username' value='".$_SESSION[''.SECURITY_SESSION.'']['username']."' readonly/></td>
					</tr>
					
					<tr>
						<td>Full Name</td>
						<td><input type='text' name='name' value='".$name."'/></td>
					</tr>
					
					<tr>
						<td>E-mail</td>
						<td><input type='text' name='email' value='".$email."'/></td>
					</tr>
					
					<tr>
						<td>Current password</td>
						<td><input type='password' name='current_password'/></td>
					</tr>
					
					<tr>
						<td>New password</td>
						<td><input type='password' name='password'/></td>
					</tr>
					
					<tr>
						<td>Re-type password</td>
						<td><input type='password' name='password2'/></td>
					</tr>

					<tr>
						<td></td>
						<td><input type='submit' value='Apply changes' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function request_account(){
		$username = $name = $email = NULL;
		
		if(isset($_POST['sbmt'])){
			$username = $_POST['username'];
			$password = $_POST['password'];
			$password2 = $_POST['password2'];
			$name = $_POST['name'];
			$email = $_POST['email'];
			
			if(empty($username) || empty($password) || empty($password2) || empty($name))
				set_message('Fill out all fields to continue.','alert',1);
			else if($password != $password2)
				set_message('Passwords do not match.','alert',1);
			else{
				if(!strstr($username,"@".ISLAND_PREFIX."")) {
					$real_username = "".$username."@".ISLAND_PREFIX."";
				} else {
					$real_username = $username;
					$username = substr($real_username, 0, strpos($real_username, "@".ISLAND_PREFIX.""));
				}
					
				$users = api_call('get_users');
				
				$admin_users = array();
				for($i = 0; $i < count($users['method_result']); $i++){
					if($users['method_result'][$i]['username'] == $real_username)
						$username_conflict = true;
					
					if($users['method_result'][$i]['admin'] == 't')
						$admin_users[] = array(
											'email' => $users['method_result'][$i]['email'],
											'name' => $users['method_result'][$i]['name']
										 );
				}

				if(isset($username_conflict))
					set_message('There is already a registered user with this Login Name.', 'error', 1);
				else{
					$data = array(
								'username' => $real_username,
								'name' => $name,
								'email' => $email,
								'password' => $password,
								'gidnumber' => ISLAND_GROUP_ID,
								'homedirectory' => '/home/'.ISLAND_PREFIX.'/'.$username.''
							);
					
					$add_user = api_call("add_user", $data);
					
					if($add_user['method_result'] == true){
						// Send email to administrators
						$subject = 'Testbed user registration';
						$message = 'You have a new user to be evaluated in the testbed:<br><br>';
						$message .= '<b>Name:</b> '.$name.'<br>';
						$message .= '<b>E-mail:</b> '.$email.'<br>';
						$message .= '<b>Institution:</b> '.ISLAND_PREFIX.'';
						
						$sender = array('email' => $email, 'name' => $name);

						if(count($admin_users) > 0)
							send_mail($sender, $admin_users, $subject, $message);
					}else
						set_message('Error in the Registration Request, try again.','error',1);
				}
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Request Account</div>
			  </div>";
		
		if(isset($add_user['method_result']) && $add_user['method_result'] == true)
			set_message('Request Registration was successful, wait for the approval of registration by administrators.','success',1);
		else{
			echo "<form method='POST' action='' id='registration'>
					<table>
						<tr>
							<td>Login Name</td>
							<td><input type='text' name='username' value='".$username."'/></td>
						</tr>
						
						<tr>
							<td>Full Name</td>
							<td><input type='text' name='name' value='".$name."'/></td>
						</tr>
						
						<tr>
							<td>E-mail</td>
							<td><input type='text' name='email' value='".$email."'/></td>
						</tr>
						
						<tr>
							<td>Password</td>
							<td><input type='password' name='password'/></td>
						</tr>
						<tr>
							<td>Re-type Password</td>
							<td><input type='password' name='password2'/></td>
						</tr>
						<tr>
							<td></td>
							<td><input type='submit' value='Request Account' name='sbmt'/></td>
						</tr>
					</table>
				</form>";
		}
	}
	
	function manager_user(){
		if(isset($_POST['remove']) && is_numeric($_POST['user_id'])){
			$remove_user = api_call("delete_user", array('user_id' => $_POST['user_id']));
			
			if ($remove_user['method_result'] == true)
				set_message('User removed successfully!','success',1);
			else
				set_message('Error to remove this user, try again.','error',1);
		}
		
		$users = api_call("get_users");
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Manager users</div>
			</div>";
			
		echo "<table id='reserve' class='table_max'>
				<tr class='top'>
					<td>Username</td>
					<td>Name</td>
					<td>Email</td>
					<td width='120px'>Actions</td>
				</tr>";
		
		for ($item = 0; $item < count($users['method_result']); $item++) {
			echo "<tr>
				<td>".$users['method_result'][$item]['username']."</td>
				<td>".$users['method_result'][$item]['name']."</td>
				<td>".$users['method_result'][$item]['email']."</td>
				<td>
					<form action='' method='GET' style='display: inline;'>
						<input type='submit' value='Edit'>
						<input type='hidden' name='page' value='edit_user'>
						<input type='hidden' name='user_id' value='".$users['method_result'][$item]['id']."'>
					</form>
					<form action='' method='POST' style='display: inline;'>
						<input type='hidden' name='remove' value='Remove'>
						<input type='button' value='Remove' onClick='confirmRemove(\"Do you really want to remove this user?\", this)'>
						<input type='hidden' name='user_id' value='".$users['method_result'][$item]['id']."'>
					</form>
				</td>
			</tr>";         
		}
		echo "</table>";
	}
	
	function edit_user(){
		if (isset($_GET['user_id']) && is_numeric($_GET['user_id'])) {
			$user_data = api_call("get_users", array('filter' => array($_GET['user_id'])));
			
			if(count($user_data['method_result']) < 1)
				Header("Location: index.php");
		}else
			Header("Location: index.php");
		
		if(isset($_POST['sbmt'])){
			$username = $_POST['username'];
			$name = $_POST['name'];
			$email = $_POST['email'];
			$password = $_POST['password'];
			$userenable = $_POST['omfenable'];
			$omfadmin = $_POST['omfadmin'];
			
			if(empty($username) || empty($name) || empty($email))
				set_message('Fill out all fields to continue.','alert',1);
			else{
				$change = array(
							"user_id" => $_GET['user_id'],
							"new_user_data" => array(
													"name" => $name,
													"email" => $email,
													"enable" => $userenable,
													"admin" => $omfadmin
											   )
						  );
				
				if(!empty($password))
					$change['new_user_data']['password'] = $password;

				$modify = api_call("update_user", $change);
				
				if($modify['method_result'] == true){
					$user_data = api_call("get_users", array('filter' => array($_GET['user_id'])));
					set_message('User edited successfully!','success',1);
				}else
					set_message('Error to edit this user, try again.','error',1);
			}
		}
		
		$username = (isset($_POST['username'])) ? $_POST['username'] : $user_data['method_result'][0]['username'];
		$name = (isset($_POST['name'])) ? $_POST['name'] : $user_data['method_result'][0]['name'];
		$email = (isset($_POST['email'])) ? $_POST['email'] : $user_data['method_result'][0]['email'];
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Edit Account - ".$username."</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>
					<tr>
						<td>Login Name</td>
						<td><input type='text' name='username' value='".$username."' readonly/></td>
					</tr>
					
					<tr>
						<td>Full Name</td>
						<td><input type='text' name='name' value='".$name."'/></td>
					</tr>
					
					<tr>
						<td>E-mail</td>
						<td><input type='text' name='email' value='".$email."'/></td>
					</tr>
					
					<tr>
						<td>Password</td>
						<td><input type='password' name='password'/></td>
					</tr>
					
					<tr>
						<td>OMF Enable</td>
						<td>
							<select name='omfenable'>";
								if($user_data['method_result'][0]['enable'] == 't'){
									echo "<option value='TRUE'>Yes</option>
									<option value='FALSE'>No</option>";
								}else{
									echo "<option value='FALSE'>No</option>
									<option value='TRUE'>Yes</option>";
								}
					echo "  </select>
						</td>
					</tr>
					<tr>
						<td>Permission</td>
						<td>
							<select name='omfadmin'>";
								if($user_data['method_result'][0]['admin'] == 't'){
									echo "<option value='TRUE'>Administrator</option>
									<option value='FALSE'>User</option>";
								}else{
									echo "<option value='FALSE'>User</option>
									<option value='TRUE'>Administrator</option>";
								}
					echo "  </select>
						</td>
					</tr>
					<tr>
						<td></td>
						<td><input type='submit' value='Apply changes' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function pendency() {
		// Actions to ldap pendencyes.
		if(isset($_POST['ldap_action']) && isset($_POST['pendency_id']) && is_numeric($_POST['pendency_id'])) {
			$resolve = api_call("resolve_ldap_pendecy", array('pendency_id' => $_POST['pendency_id']));
				
			if($resolve['method_result'] == true)
				set_message('Pendency resolved successfully!','success',1);
			else
				set_message('Error to resolve this pendency, try again.','error',1);
		}
		
		// Actions from users pendencyes.
		if(isset($_POST['action'])) {
			$user_id = $_POST['user_id'];
			
			if($_POST['action'] == 'Accept'){
				$change = array(
							"user_id" => $user_id,
							"new_user_data" => array(
													"enable" => 'TRUE'
											   )
						  );

				$modify = api_call("update_user", $change);
				
				if($modify['method_result'] == true){
					$subject = 'Testbed user registration';
					$message = 'Your account request has been <b>approved</b>!';
						
					set_message('User approved successfully!','success',1);
				}else
					set_message('Error to approve this user, try again.','error',1);
			}else if($_POST['action'] == 'Refuse'){
				$remove = api_call("delete_user", array('user_id' => $user_id));
				
				if ($remove['method_result'] == true){
					$subject = 'Testbed user registration';
					$message = 'Your account request has been <b>reproved</b></b><br>contact your testbed administrator';
					
					set_message('User refused successfully!','success',1);
				}else
					set_message('Error to refuse this user, try again.','error',1);
			}
			
			// Send e-mail to the user informing the approval of registration
			if($remove || $modify){	
				$user_and_admin = api_call("get_users", array("filter" => array($user_id, $_SESSION[''.SECURITY_SESSION.'']['user_id'])));
				
				$receiver = $sender = array();
				for($i = 0; $i < count($user_and_admin['method_result']); $i++){
					$mail_data = array('email' => $user_and_admin['method_result'][$i]['email'],
										'name' => $user_and_admin['method_result'][$i]['name']);
										
					if($user_and_admin['method_result'][$i]['id'] == $_SESSION[''.SECURITY_SESSION.'']['user_id'])
						$sender = $mail_data;
					else
						$receiver[0] = $mail_data;
				}
			  
				send_mail($sender, $receiver, $subject, $message);
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Island pending</div>
			</div>";
			
		// Users pendency
		$users = api_call("get_users");
		$pending_users = array();
		
		for($i = 0; $i < count($users['method_result']); $i++){
			if($users['method_result'][$i]['enable'] == 'f')
				$pending_users[] = $users['method_result'][$i];
		}
		
		echo "<div class='institution_title2'>Users pending</div>";
		
		echo "<table id='reserve' class='table_max'>
				<tr class='top'>
					<td>Username</td>
					<td>Name</td>
					<td>Email</td>
					<td width='125px'>Actions</td>
				</tr>";
				
		if(count($pending_users) <= 0){
			echo "<tr>
				<td colspan='4'>You have no users to evaluate.</td>
			</tr>";
		}
		
		for ($item = 0; $item < count($pending_users); $item++) {
			echo "<tr>
				<td>".$pending_users[$item]['username']."</td>
				<td>".$pending_users[$item]['name']."</td>
				<td>".$pending_users[$item]['email']."</td>
				<td>
					<form action='' method='POST' style='display: inline;'>
						<input type='submit' name='action' value='Accept'>
						<input type='hidden' name='user_id' value='".$pending_users[$item]['id']."'>
					</form>
					<form action='' method='POST' style='display: inline;'>
						<input type='submit' name='action' value='Refuse'>
						<input type='hidden' name='user_id' value='".$pending_users[$item]['id']."'>
					</form>
				</td>
			</tr>";           
		}
		echo "</table>";
		
		// LDAP Pendency		
		$ldap_pendencies = api_call("get_ldap_pendencies");
		$ldap_pendencies = $ldap_pendencies['method_result'];
		
		echo "<div class='institution_title2'>LDAP pending</div>";
		
		echo "<table id='reserve' class='table_max'>
				<tr class='top'>
					<td>ID</td>
					<td>Type</td>
					<td>User</td>
					<td>Error Description</td>
					<td width='125px'>Actions</td>
				</tr>";
				
		if(count($ldap_pendencies) <= 0){
			echo "<tr>
				<td colspan='5'>You have no ldap pendings to resolve.</td>
			</tr>";
		}
		
		for ($item = 0; $item < count($ldap_pendencies); $item++) {
			echo "<tr>
				<td>".$ldap_pendencies[$item]['id']."</td>
				<td>".$ldap_pendencies[$item]['action']."</td>
				<td>".$ldap_pendencies[$item]['username']."</td>
				<td>".$ldap_pendencies[$item]["error_description"]."</td>
				<td>
					<form action='' method='POST' style='display: inline;'>
						<input type='submit' name='ldap_action' value='Resolve'>
						<input type='hidden' name='pendency_id' value='".$ldap_pendencies[$item]['id']."'>
					</form>
				</td>
			</tr>";           
		}
		echo "</table>";
	}
	
	function manager_resources(){
		if(isset($_POST['remove']) && is_numeric($_POST['resource_id'])){
			$remove_resource = api_call("delete_resource", array('resource_id' => $_POST['resource_id']));
			
			if ($remove_resource['method_result'] == true)
				set_message('Resource removed successfully!','success',1);
			else
				set_message('Error to remove this resource, try again.','error',1);
		}
		
		$resources = api_call("get_resources");
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Manager resources</div>
			</div>";
			
		echo "<table id='reserve' class='table_max'>
				<tr class='add_menu'>
					<td colspan='4'>
						<a class='button' href='index.php?page=add_resource'>Add resource</a>
						<a class='button' href='index.php?page=manager_pxeimages'>Manager pxeimages</a>
						<a class='button' href='index.php?page=manager_motherboards'>Manager motherboards</a>
					</td>
				</tr>
				
				<tr class='top'>
					<td>ID</td>
					<td>Type</td>
					<td>Name</td>
					<td width='120px'>Actions</td>
				</tr>";
				
		if(count($resources['method_result']) <= 0){
			echo "<tr>
				<td colspan='4'>You have no resources.</td>
			</tr>";
		}
		
		for ($item = 0; $item < count($resources['method_result']); $item++) {
			echo "<tr>
				<td>".$resources['method_result'][$item]['id']."</td>
				<td>".$resources['method_result'][$item]['type']."</td>";
				
				if($resources['method_result'][$item]['type'] == 'node')
					echo "<td>".$resources['method_result'][$item]['resource_details']['hostname']."</td>";
				else
					echo "<td>".ucfirst($resources['method_result'][$item]['type'])." ".$resources['method_result'][$item]['resource_details']['channel_number']."</td>";
					
				echo "<td>
					<form action='' method='GET' style='display: inline;'>
						<input type='submit' value='Edit'>
						<input type='hidden' name='page' value='edit_resource'>
						<input type='hidden' name='resource_id' value='".$resources['method_result'][$item]['id']."'>
					</form>
					<form action='' method='POST' style='display: inline;'>
						<input type='hidden' name='remove' value='Remove'>
						<input type='button' value='Remove' onClick='confirmRemove(\"Do you really want to remove this resource?\", this)'>
						<input type='hidden' name='resource_id' value='".$resources['method_result'][$item]['id']."'>
					</form>
				</td>
			</tr>";         
		}
		echo "</table>";
	}
	
	function add_resource(){
		$type = (isset($_POST['type'])) ? $_POST['type'] : "node";
		
		$all_fields = array(
						'control_ip' => 'Control IP',
						'control_mac' => 'Control MAC',
						'cmc_ip' => 'CMC IP',
						'hostname' => 'Hostname',
						'hrn' => 'HRN',
						'chassis_sn' => 'Chassis number',
						'motherboard_id' => 'Motherboard',
						'pxeimage_id' => 'Pxeimage',
						'disk' => 'Disk',
						'modulation' => 'Modulation',
						'channel_number' => 'Channel number',
						'frequency' => 'Frequency'
					  );
					
		$node_fields = array('control_ip', 'control_mac', 'cmc_ip', 'hostname', 'hrn', 'chassis_sn', 'motherboard_id', 'pxeimage_id', 'disk');
		$channel_fields = array('modulation', 'channel_number', 'frequency');
		
		if(isset($_POST['sbmt'])){
			$empty = false;
			
			if($type == 'node')
				$fields = $node_fields;
			else
				$fields = $channel_fields;
			
			for($i = 0; $i < count($fields); $i++){
				$field_name = $fields[$i];
				
				if(empty($_POST[''.$field_name.'']))
					$empty = true;
			}
			
			if($empty)
				set_message('Fill out all fields to continue.','alert',1);
			else{
				$new_resource = array("type" => $type);
				
				for($i = 0; $i < count($fields); $i++){
					$field_name = $fields[$i];
					$new_resource['resource_data'][''.$field_name.''] = $_POST[''.$field_name.''];
				}

				$add_resource = api_call("add_resource", $new_resource);
				
				if($add_resource['method_result'] == true)
					set_message('Resource added successfully!','success',1);
				else
					set_message('Error to add this resource, try again.','error',1);
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Add resource</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>
					<tr>
						<td>Resource type</td>
						<td>
							<select name='type' onchange='changeResourceType(this.value)'>";
								$resource_types = array('node', 'channel');
								
								for($i = 0; $i < count($resource_types); $i++){
									$selected = ($resource_types[$i] == $type) ? 'selected' : "";
									echo "<option value='".$resource_types[$i]."' ".$selected.">".ucfirst($resource_types[$i])."</option>";
								}
								
				echo "</select></td>";

				for($i = 0; $i < count($all_fields); $i++){
					$field_name = array_keys($all_fields)[$i];
					
					$resource_value = (isset($_POST[''.$field_name.'']) ? $_POST[''.$field_name.''] : "");
					
					if(in_array($field_name, $node_fields, true))
						$field_type = "node_fields";
					else
						$field_type = "channel_fields";
						
					echo "<tr class='".$field_type."'>
							<td>".$all_fields[''.$field_name.'']."</td>
							<td>";
					
					switch($field_name){
						case 'modulation':
							$modulations = array('IEEE802_11a' => '802.11a', 'IEEE802_11b_g' => '802.11b/g');
							
							echo "<select name='".$field_name."'>
									<option value=''>[Select]</option>
								";
									for($j = 0; $j < count($modulations); $j++){
										$modulation_name = array_keys($modulations)[$j];
										$selected = ($modulation_name == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$modulation_name."' ".$selected.">".$modulations[''.$modulation_name.'']."</option>";
									}
							echo "</select>";
							break;
						case 'motherboard_id':
							$motherboards = api_call("get_motherboards");
							
							echo "<select name='".$field_name."'>
									<option value=''>[Select]</option>
								";
									for($j = 0; $j < count($motherboards['method_result']); $j++){
										$selected = ($motherboards['method_result'][$j]['id'] == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$motherboards['method_result'][$j]['id']."' ".$selected.">".$motherboards['method_result'][$j]['cpu_number']."</option>";
									}
							echo "</select>";
							break;
						case 'pxeimage_id':
							$pxeimages = api_call("get_pxeimages");
							
							echo "<select name='".$field_name."'>
									<option value=''>[Select]</option>
								";
									for($j = 0; $j < count($pxeimages['method_result']); $j++){
										$selected = ($pxeimages['method_result'][$j]['id'] == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$pxeimages['method_result'][$j]['id']."' ".$selected.">".$pxeimages['method_result'][$j]['image_name']."</option>";
									}
							echo "</select>";
							break;
						default:
							echo "<input type='text' name='".$field_name."' value='".$resource_value."'/>";
							break;
					}
					
					echo "</td></tr>";
				}
				
				echo "<tr>
						<td></td>
						<td><input type='submit' value='Add resource' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
		
		echo "<script type='text/javascript'>changeResourceType('".$type."');</script>";
	}
	
	function edit_resource(){
		if (isset($_GET['resource_id']) && is_numeric($_GET['resource_id'])) {
			$resource_data = api_call("get_resources", array('filter' => array($_GET['resource_id'])));
			
			if(count($resource_data['method_result']) != 1)
				Header("Location: index.php");
		}else
			Header("Location: index.php");
		
		switch($resource_data['method_result'][0]['type']){
			case "node":
				$fields = array(
							'control_ip' => 'Control IP',
							'control_mac' => 'Control MAC',
							'cmc_ip' => 'CMC IP',
							'hostname' => 'Hostname',
							'hrn' => 'HRN',
							'chassis_sn' => 'Chassis number',
							'motherboard_id' => 'Motherboard',
							'pxeimage_id' => 'Pxeimage',
							'disk' => 'Disk',
							'status' => 'Status'
						  );
				break;
			case "channel":
				$fields = array(
							'modulation' => 'Modulation',
							'channel_number' => 'Channel number',
							'frequency' => 'Frequency',
							'status' => 'Status'
						  );
				break;
		}
		
		if(isset($_POST['sbmt'])){
			$empty = false;
			for($i = 0; $i < count($fields); $i++){
				$field_name = array_keys($fields)[$i];
				
				if($field_name == 'status' && is_numeric($_POST[''.$field_name.'']))
					break;
					
				if(empty($_POST[''.$field_name.'']))
					$empty = true;
			}
			
			if($empty)
				set_message('Fill out all fields to continue.','alert',1);
			else{
				$change = array("resource_id" => $_GET['resource_id']);
				
				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					$change['resource_new_data'][''.$field_name.''] = $_POST[''.$field_name.''];
				}

				$modify = api_call("update_resource", $change);
				
				if($modify['method_result'] == true)
					set_message('Resource edited successfully!','success',1);
				else
					set_message('Error to edit this resource, try again.','error',1);
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Edit resource #".$resource_data['method_result'][0]['id']."</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>";

				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					
					$resource_value = (isset($_POST[''.$field_name.'']) ? $_POST[''.$field_name.''] : (($field_name == 'status') ? $resource_data['method_result'][0]['status'] : $resource_data['method_result'][0]['resource_details'][''.$field_name.'']));
					
					echo "<tr>
							<td>".$fields[''.$field_name.'']."</td>
							<td>";
					
					switch($field_name){
						case 'modulation':
							$modulations = array('IEEE802_11a' => '802.11a', 'IEEE802_11b_g' => '802.11b/g');
							
							echo "<select name='".$field_name."'>";
									for($j = 0; $j < count($modulations); $j++){
										$modulation_name = array_keys($modulations)[$j];
										$selected = ($modulation_name == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$modulation_name."' ".$selected.">".$modulations[''.$modulation_name.'']."</option>";
									}
							echo "</select>";
							break;
						case 'status':
							$status = array('0' => 'OK', '1' => 'Maintenance');

							echo "<select name='".$field_name."'>";
									for($j = 0; $j < count($status); $j++){
										$status_name = array_keys($status)[$j];
										$selected = ($status_name == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$status_name."' ".$selected.">".$status[''.$status_name.'']."</option>";
									}
							echo "</select>";
							break;
						case 'motherboard_id':
							$motherboards = api_call("get_motherboards");
							
							echo "<select name='".$field_name."'>";
									for($j = 0; $j < count($motherboards['method_result']); $j++){
										$selected = ($motherboards['method_result'][$j]['id'] == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$motherboards['method_result'][$j]['id']."' ".$selected.">".$motherboards['method_result'][$j]['cpu_number']."</option>";
									}
							echo "</select>";
							break;
						case 'pxeimage_id':
							$pxeimages = api_call("get_pxeimages");
							
							echo "<select name='".$field_name."'>";
									for($j = 0; $j < count($pxeimages['method_result']); $j++){
										$selected = ($pxeimages['method_result'][$j]['id'] == $resource_value) ? 'selected' : "";
										
										echo "<option value='".$pxeimages['method_result'][$j]['id']."' ".$selected.">".$pxeimages['method_result'][$j]['image_name']."</option>";
									}
							echo "</select>";
							break;
						default:
							echo "<input type='text' name='".$field_name."' value='".$resource_value."'/>";
							break;
					}
					
					echo "</td></tr>";
				}
				
				echo "<tr>
						<td></td>
						<td><input type='submit' value='Apply changes' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function manager_pxeimages(){
		if(isset($_POST['remove']) && is_numeric($_POST['pxeimage_id'])){
			$remove_pxeimage = api_call("delete_pxeimage", array('pxeimage_id' => $_POST['pxeimage_id']));
			
			if ($remove_pxeimage['method_result'] == true)
				set_message('Pxeimage removed successfully!','success',1);
			else
				set_message('Error to remove this pxeimage, try again.','error',1);
		}
		
		$pxeimages = api_call("get_pxeimages");
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Manager pxeimages</div>
			</div>";
			
		echo "<table id='reserve' class='table_max'>
				<tr class='add_menu'>
					<td colspan='4'>
						<a class='button' href='index.php?page=add_pxeimage'>Add pxeimage</a>
					</td>
				</tr>
				
				<tr class='top'>
					<td>ID</td>
					<td>Image name</td>
					<td width='120px'>Actions</td>
				</tr>";
		
		if(count($pxeimages['method_result']) <= 0){
			echo "<tr>
				<td colspan='4'>You have no pxeimages.</td>
			</tr>";
		}
		
		for ($item = 0; $item < count($pxeimages['method_result']); $item++) {
			echo "<tr>
				<td>".$pxeimages['method_result'][$item]['id']."</td>
				<td>".$pxeimages['method_result'][$item]['image_name']."</td>
				<td>
					<form action='' method='GET' style='display: inline;'>
						<input type='submit' value='Edit'>
						<input type='hidden' name='page' value='edit_pxeimage'>
						<input type='hidden' name='pxeimage_id' value='".$pxeimages['method_result'][$item]['id']."'>
					</form>
					<form action='' method='POST' style='display: inline;'>
						<input type='hidden' name='remove' value='Remove'>
						<input type='button' value='Remove' onClick='confirmRemove(\"Do you really want to remove this pxeimage?\", this)'>
						<input type='hidden' name='pxeimage_id' value='".$pxeimages['method_result'][$item]['id']."'>
					</form>
				</td>
			</tr>";         
		}
		echo "</table>";
	}
	
	function add_pxeimage(){
		$fields = array(
						'image_name' => 'Image name',
						'short_description' => 'Description'
					   );
					
		if(isset($_POST['sbmt'])){
			$empty = false;
			
			for($i = 0; $i < count($fields); $i++){
				$field_name = array_keys($fields)[$i];
				
				if(empty($_POST[''.$field_name.'']))
					$empty = true;
			}
			
			if($empty)
				set_message('Fill out all fields to continue.','alert',1);
			else{
				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					$new_pxeimage['pxeimage_data'][''.$field_name.''] = $_POST[''.$field_name.''];
				}

				$add_pxeimage = api_call("add_pxeimage", $new_pxeimage);
				
				if($add_pxeimage['method_result'] == true)
					set_message('Pxeimage added successfully!','success',1);
				else
					set_message('Error to add this pxeimage, try again.','error',1);
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Add pxeimage</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>";

				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					
					$resource_value = (isset($_POST[''.$field_name.'']) ? $_POST[''.$field_name.''] : "");
					
					echo "<tr>
							<td>".$fields[''.$field_name.'']."</td>
							<td>";
					
					switch($field_name){
						case "short_description":
							echo "<textarea name='".$field_name."'>".$resource_value."</textarea>";
							break;
						default:
							echo "<input type='text' name='".$field_name."' value='".$resource_value."'/>";
							break;
					}
					
					echo "</td></tr>";
				}
				
				echo "<tr>
						<td></td>
						<td><input type='submit' value='Add pxeimage' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function edit_pxeimage(){
		if (isset($_GET['pxeimage_id']) && is_numeric($_GET['pxeimage_id'])) {
			$pxeimage_data = api_call("get_pxeimages", array('filter' => array($_GET['pxeimage_id'])));
			
			if(count($pxeimage_data['method_result']) != 1)
				Header("Location: index.php");
		}else
			Header("Location: index.php");
		
		$fields = array(
						'image_name' => 'Image name',
						'short_description' => 'Description'
					   );
					
		if(isset($_POST['sbmt'])){
			$empty = false;
			
			for($i = 0; $i < count($fields); $i++){
				$field_name = array_keys($fields)[$i];
				
				if(empty($_POST[''.$field_name.'']))
					$empty = true;
			}
			
			if($empty)
				set_message('Fill out all fields to continue.','alert',1);
			else{
				$change = array("pxeimage_id" => $_GET['pxeimage_id']);
				
				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					$change['pxeimage_new_data'][''.$field_name.''] = $_POST[''.$field_name.''];
				}

				$update_pxeimage = api_call("update_pxeimage", $change);
				
				if($update_pxeimage['method_result'] == true)
					set_message('Pxeimage edited successfully!','success',1);
				else
					set_message('Error to edit this pxeimage, try again.','error',1);
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Edit pxeimage #".$pxeimage_data['method_result'][0]['id']."</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>";

				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					
					$resource_value = (isset($_POST[''.$field_name.'']) ? $_POST[''.$field_name.''] : $pxeimage_data['method_result'][0][''.$field_name.'']);
					
					echo "<tr>
							<td>".$fields[''.$field_name.'']."</td>
							<td>";
					
					switch($field_name){
						case "short_description":
							echo "<textarea name='".$field_name."'>".$resource_value."</textarea>";
							break;
						default:
							echo "<input type='text' name='".$field_name."' value='".$resource_value."'/>";
							break;
					}
					
					echo "</td></tr>";
				}
				
				echo "<tr>
						<td></td>
						<td><input type='submit' value='Apply changes' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function manager_motherboards(){
		if(isset($_POST['remove']) && is_numeric($_POST['motherboard_id'])){
			$remove_motherboard = api_call("delete_motherboard", array('motherboard_id' => $_POST['motherboard_id']));
			
			if ($remove_motherboard['method_result'] == true)
				set_message('Motherboard removed successfully!','success',1);
			else
				set_message('Error to remove this motherboard, try again.','error',1);
		}
		
		$motherboards = api_call("get_motherboards");
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Manager motherboards</div>
			</div>";
			
		echo "<table id='reserve' class='table_max'>
				<tr class='add_menu'>
					<td colspan='6'>
						<a class='button' href='index.php?page=add_motherboard'>Add motherboard</a>
					</td>
				</tr>
				
				<tr class='top'>
					<td>ID</td>
					<td>CPU type</td>
					<td>CPU number</td>
					<td>HD size</td>
					<td>Memory</td>
					<td width='120px'>Actions</td>
				</tr>";
		
		if(count($motherboards['method_result']) <= 0){
			echo "<tr>
				<td colspan='6'>You have no motherboards.</td>
			</tr>";
		}
		
		for ($item = 0; $item < count($motherboards['method_result']); $item++) {
			echo "<tr>
				<td>".$motherboards['method_result'][$item]['id']."</td>
				<td>".$motherboards['method_result'][$item]['cpu_type']."</td>
				<td>".$motherboards['method_result'][$item]['cpu_number']."</td>
				<td>".$motherboards['method_result'][$item]['hd_size']."</td>
				<td>".$motherboards['method_result'][$item]['memory']."</td>
				<td>
					<form action='' method='GET' style='display: inline;'>
						<input type='submit' value='Edit'>
						<input type='hidden' name='page' value='edit_motherboard'>
						<input type='hidden' name='motherboard_id' value='".$motherboards['method_result'][$item]['id']."'>
					</form>
					<form action='' method='POST' style='display: inline;'>
						<input type='hidden' name='remove' value='Remove'>
						<input type='button' value='Remove' onClick='confirmRemove(\"Do you really want to remove this motherboard?\", this)'>
						<input type='hidden' name='motherboard_id' value='".$motherboards['method_result'][$item]['id']."'>
					</form>
				</td>
			</tr>";         
		}
		echo "</table>";
	}
	
	function add_motherboard(){
		$fields = array(
						'cpu_type' => 'CPU type',
						'cpu_number' => 'CPU number',
						'cpu_hz' => 'CPU Hz',
						'hd_size' => 'HD size',
						'memory' => 'Memory'
					   );
					
		if(isset($_POST['sbmt'])){
			$empty = false;
			
			for($i = 0; $i < count($fields); $i++){
				$field_name = array_keys($fields)[$i];
				
				if(empty($_POST[''.$field_name.'']))
					$empty = true;
			}
			
			if($empty)
				set_message('Fill out all fields to continue.','alert',1);
			else{
				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					$new_motherboard['motherboard_data'][''.$field_name.''] = $_POST[''.$field_name.''];
				}

				$add_motherboard = api_call("add_motherboard", $new_motherboard);
				
				if($add_motherboard['method_result'] == true) {
					set_message('Motherboard added successfully!','success',1);
				} else {
					set_message('Error to add this motherboard, try again.','error',1);
				}
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Add motherboard</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>";

				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					
					$resource_value = (isset($_POST[''.$field_name.'']) ? $_POST[''.$field_name.''] : "");
					
					echo "<tr>
							<td>".$fields[''.$field_name.'']."</td>
							<td><input type='text' name='".$field_name."' value='".$resource_value."'/></td>
						  </tr>";
				}
				
				echo "<tr>
						<td></td>
						<td><input type='submit' value='Add motherboard' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function edit_motherboard(){
		if (isset($_GET['motherboard_id']) && is_numeric($_GET['motherboard_id'])) {
			$motherboard_data = api_call("get_motherboards", array('filter' => array($_GET['motherboard_id'])));
			
			if(count($motherboard_data['method_result']) != 1)
				Header("Location: index.php");
		}else
			Header("Location: index.php");
		
		$fields = array(
						'cpu_type' => 'CPU type',
						'cpu_number' => 'CPU number',
						'cpu_hz' => 'CPU Hz',
						'hd_size' => 'HD size',
						'memory' => 'Memory'
					   );
					
		if(isset($_POST['sbmt'])){
			$empty = false;
			
			for($i = 0; $i < count($fields); $i++){
				$field_name = array_keys($fields)[$i];
				
				if(empty($_POST[''.$field_name.'']))
					$empty = true;
			}
			
			if($empty)
				set_message('Fill out all fields to continue.','alert',1);
			else{
				$change = array("motherboard_id" => $_GET['motherboard_id']);
				
				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					$change['motherboard_new_data'][''.$field_name.''] = $_POST[''.$field_name.''];
				}

				$update_motherboard = api_call("update_motherboard", $change);
				
				if($update_motherboard['method_result'] == true)
					set_message('Motherboard edited successfully!','success',1);
				else
					set_message('Error to edit this motherboard, try again.','error',1);
			}
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Edit motherboard #".$motherboard_data['method_result'][0]['id']."</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>";

				for($i = 0; $i < count($fields); $i++){
					$field_name = array_keys($fields)[$i];
					
					$resource_value = (isset($_POST[''.$field_name.'']) ? $_POST[''.$field_name.''] : $motherboard_data['method_result'][0][''.$field_name.'']);
					
					echo "<tr>
							<td>".$fields[''.$field_name.'']."</td>
							<td><input type='text' name='".$field_name."' value='".$resource_value."'/></td>
						  </tr>";
				}
				
				echo "<tr>
						<td></td>
						<td><input type='submit' value='Apply changes' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function forgot_password(){
		if(isset($_POST['sbmt'])){
			$username = $_POST['username'];

			if(!strstr($username,"@".ISLAND_PREFIX.""))
				$username = "".$username."@".ISLAND_PREFIX."";

			$user_id = api_call("get_user_id_by_username", array('username' => $username));
				
			if(is_numeric($user_id['method_result'])){
				// Generate a new password and change it
				$new_password = substr(md5(uniqid(time(), true)), 0, 12);
				
				$change = array(
							"user_id" => $user_id['method_result'],
							"new_user_data" => array(
													"password" => $new_password
											   )
						  );

				$modify = api_call("update_user", $change);
				
				if($modify['method_result'] == true){
					// Send e-mail to the user
					$subject = 'Testbed password recovery';
					$message = 'You requested a password recovery in testbed.<br>'.
							   'New password: <b>'.$new_password.'</b>';
					
					$user_data = api_call("get_users", array("filter" => array($user_id['method_result'])));
					$receiver[0] = array('email' => $user_data['method_result'][0]['email'],
										 'name' => $user_data['method_result'][0]['name']);
									
					$sender = $receiver[0];
										  
					send_mail($sender, $receiver, $subject, $message);
					set_message('Password changed successfully, please check your email to learn your new password','success',1);
				}else
					set_message('An error occurred, please try again','error',1);
			}else
				set_message('User not found.','error',1);	
		}
		
		echo "<div id='text'>
				<div class='title'>".bread_crumbs(NULL, TRUE)." Recover a forgotten password</div>
			  </div>";
		
		echo "<form method='POST' action='' id='registration'>
				<table>
					<tr>
						<td>Login Name</td>
						<td><input type='text' name='username'/></td>
					</tr>
					<tr>
						<td></td>
						<td><input type='submit' value='Recover' name='sbmt'/></td>
					</tr>
				</table>
			</form>";
	}
	
	function logout(){
		session_unset();
		header("Location: index.php");
	}
?>
